
<title>Add Item Page</title>


<?php  

/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
  
require_once "../services/webservices.php";
require_once "index.php";  
?>
     
<form action="additem.php"  method="POST" name="get_Category"> 
 
<script type="text/javascript">
function addItem()
{
    go=true;
    if(document.getElementById("general_description").value=='' || document.getElementById("description").value=='' || document.getElementById("imageurl").value=='' || document.getElementById("price").value=='' || document.getElementById("instock").value=='')
        {
        alert("Please completely fill out form.");
        go = false;
        return false;
        }
    if(go)
        {        
        return true;
        }
}
</script>    
<br />

 
 <?php
if (isset($_POST["imageurl"]))
{   
   
     $addRequest=new item();
     $addRequest->category_id=$_POST["additem"];  
     $addRequest->item_name=$_POST["item_name"];   
     $addRequest->general_description=$_POST["general_description"];
     $addRequest->description=$_POST["description"];               
     $addRequest->imageurl=$_POST["imageurl"];     
     $addRequest->price=$_POST["price"];  
     $addRequest->instock=$_POST["instock"]; 
     $addRequest->packing = $_POST['packing'];  
     $addRequest->weight = $_POST['weight'];
     $addResponse = $addRequest->additem();
     $xml = new SimpleXMLElement($addResponse);
     $added = $xml->added;
     $item_id = $xml->item_id;
     
     if ($item_id)
     {
        echo "<br /><b>Item was Added<br /><br /></b>";
       
     }
     else
     {
        echo "<br /><b>Error Trying To Add Item<br /><br /></b>";
     }

    
         
         
} 
 ?> 
<br />   
<div class="leftfloatbar">
 <b>Category Selection</b>
<hr>


 <select name="additem">    
<?php

 
   
   
 

$getRequest = new itemcategory();
$getResponse = $getRequest->getallitemcategories();       
$xml = new SimpleXMLElement($getResponse);
$Item_Count = $xml->Item_Count;
 
if($Item_Count > 0)
{
   
    foreach ($xml->Item as $eachItem)         
    {
        $category_id = $eachItem->category_id;
        $category = $eachItem->category;            
?>
<option value="<?php echo $category_id;?>" ><?php echo $category;?></option>
<?php
}
}
else
{
      
?>   
<option value="0">No Categories Found.</option>
<?php
} 
       
?>

 </select> 
 </div>
<br />      
<br /> 
<br />      
<br /> 
<br /> 
<br /> 
<?php
if($Item_Count > 0)
{
    

?>
<b>Fill Out Item Information</b>


<div class="doubleborderrightmargin">

Item Name:
<br />
<input type="text" name="item_name" id="item_name"> 
<br />    
General Description:
<br />      
<input type="text" name="general_description" id="general_description">
<br />       
Description:
<br />        
<input type="text" name="description" id="description">
<br />       
Image URL:
<br />        
<input type="text" name="imageurl" id="imageurl">
<br />        
Price:
<br />     
<input type="text" name="price" id="price">
<br />       
Number In Stock:
<br />      
<input type="text" name="instock" id="instock">
<br />  
Packing:
<br />    
<select name="packing">
    <option value="alone">alone</option>
    <option value="grouped">grouped</option>
</select>
<br />

Weight:
<br />      
<input type="text" name="weight" id="weight">
<br />    
<br />    
   
  

    
<input type="submit" id="btnInsert_Item" value="Insert Item" onclick="javascript: return addItem();">
<br />
<br />
 <br />
 <br />
  
</div>
</div>

   </div>
<?php
}
else
{
    echo '<b>Please Add At Least One Category Before Trying To Create A Product</b>';
}
?>  



</form>


